package com.windfone.web.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.windfone.common.OrderUtil;
import com.windfone.model.Color;
import com.windfone.model.DetailMsg;
import com.windfone.model.PackageCompose;
import com.windfone.model.Pricehistory;
import com.windfone.model.ProductBase;
import com.windfone.model.ProductCameraFunc;
import com.windfone.model.ProductDigiFunc;
import com.windfone.model.ProductMultimediaFunc;
import com.windfone.service.CommonService;
import com.windfone.service.ProductExtendService;

public class ProductExtendAction extends ActionSupport {
	/**	serialVersionUID  */
	private static final long serialVersionUID = 1L;

	private ProductExtendService productExtendService;
	private CommonService commonService;
	private String addressBook;
	private String messageFuns;
	private String emailFuns;
	private String inputMethod;
	private String game;
	private String officeFuns;
	private String recording;
	private String mainFunction;
	private String otherFuns;
	private String waitTime;
	private String ring;
	
	private String header;
	private String pixel;
	private String sensorType;
	private String flash;
	private String special;
	private String videa;
	private String photoQuality;
	private String photoEffects;
	private String captureMode;
	private String secondHeader;
	
	private String bluetooth;
	private String dataService;
	private String javafunctions;
	private String wap;
	private String www;
	private String dataline;
	private String extendsCard;
	private String wifiwlan;
	private String gpsDetail;
	private String otherdigit;
	
	private String multimedia;
	private String mp3player;
	private String videaplayer;
	private String fmRadio;
	private String flashplayer;
	private String streamingMedia;
	
	private int id;
	private int langId;
	private int productId;
	
	private ProductBase productBase;
	private ProductCameraFunc productCameraFunc;
	private ProductDigiFunc productDigiFunc;
	private ProductMultimediaFunc productMultimediaFunc;
	
	public ProductBase getProductBase() {
		return productBase;
	}

	public ProductCameraFunc getProductCameraFunc() {
		return productCameraFunc;
	}

	public String getPhotoQuality() {
		return photoQuality;
	}

	public String getPhotoEffects() {
		return photoEffects;
	}

	public String getCaptureMode() {
		return captureMode;
	}

	public String getSecondHeader() {
		return secondHeader;
	}

	public void setPhotoQuality(String photoQuality) {
		this.photoQuality = photoQuality;
	}

	public void setPhotoEffects(String photoEffects) {
		this.photoEffects = photoEffects;
	}

	public void setCaptureMode(String captureMode) {
		this.captureMode = captureMode;
	}

	public void setCommonService(CommonService commonService) {
		this.commonService = commonService;
	}

	public void setSecondHeader(String secondHeader) {
		this.secondHeader = secondHeader;
	}

	public ProductDigiFunc getProductDigiFunc() {
		return productDigiFunc;
	}

	public ProductMultimediaFunc getProductMultimediaFunc() {
		return productMultimediaFunc;
	}

	public void setProductBase(ProductBase productBase) {
		this.productBase = productBase;
	}

	public void setProductCameraFunc(ProductCameraFunc productCameraFunc) {
		this.productCameraFunc = productCameraFunc;
	}

	public void setProductDigiFunc(ProductDigiFunc productDigiFunc) {
		this.productDigiFunc = productDigiFunc;
	}

	public void setProductMultimediaFunc(ProductMultimediaFunc productMultimediaFunc) {
		this.productMultimediaFunc = productMultimediaFunc;
	}

	public String getAddressBook() {
		return addressBook;
	}

	public String getRing() {
		return ring;
	}

	public String getStreamingMedia() {
		return streamingMedia;
	}

	public void setStreamingMedia(String streamingMedia) {
		this.streamingMedia = streamingMedia;
	}

	public void setRing(String ring) {
		this.ring = ring;
	}

	public void setAddressBook(String addressBook) {
		this.addressBook = addressBook;
	}

	public String getMessageFuns() {
		return messageFuns;
	}

	public void setMessageFuns(String messageFuns) {
		this.messageFuns = messageFuns;
	}

	public String getEmailFuns() {
		return emailFuns;
	}

	public void setEmailFuns(String emailFuns) {
		this.emailFuns = emailFuns;
	}

	public String getInputMethod() {
		return inputMethod;
	}

	public void setInputMethod(String inputMethod) {
		this.inputMethod = inputMethod;
	}

	public String getGame() {
		return game;
	}

	public void setGame(String game) {
		this.game = game;
	}

	public String getOfficeFuns() {
		return officeFuns;
	}

	public void setOfficeFuns(String officeFuns) {
		this.officeFuns = officeFuns;
	}

	public String getRecording() {
		return recording;
	}

	public void setRecording(String recording) {
		this.recording = recording;
	}

	public String getMainFunction() {
		return mainFunction;
	}

	public void setMainFunction(String mainFunction) {
		this.mainFunction = mainFunction;
	}

	public String getOtherFuns() {
		return otherFuns;
	}

	public void setOtherFuns(String otherFuns) {
		this.otherFuns = otherFuns;
	}

	public String getWaitTime() {
		return waitTime;
	}

	public void setWaitTime(String waitTime) {
		this.waitTime = waitTime;
	}

	public String getHeader() {
		return header;
	}

	public void setHeader(String header) {
		this.header = header;
	}

	public String getPixel() {
		return pixel;
	}

	public void setPixel(String pixel) {
		this.pixel = pixel;
	}

	public String getSensorType() {
		return sensorType;
	}

	public void setSensorType(String sensorType) {
		this.sensorType = sensorType;
	}

	public String getFlash() {
		return flash;
	}

	public void setFlash(String flash) {
		this.flash = flash;
	}

	public String getSpecial() {
		return special;
	}

	public void setSpecial(String special) {
		this.special = special;
	}

	public String getVidea() {
		return videa;
	}

	public void setVidea(String videa) {
		this.videa = videa;
	}

	public String getBluetooth() {
		return bluetooth;
	}

	public void setBluetooth(String bluetooth) {
		this.bluetooth = bluetooth;
	}

	public String getDataService() {
		return dataService;
	}

	public void setDataService(String dataService) {
		this.dataService = dataService;
	}

	public String getJavafunctions() {
		return javafunctions;
	}

	public void setJavafunctions(String javafunctions) {
		this.javafunctions = javafunctions;
	}

	public String getWap() {
		return wap;
	}

	public void setWap(String wap) {
		this.wap = wap;
	}

	public String getWww() {
		return www;
	}

	public void setWww(String www) {
		this.www = www;
	}

	public String getDataline() {
		return dataline;
	}

	public void setDataline(String dataline) {
		this.dataline = dataline;
	}

	public String getExtendsCard() {
		return extendsCard;
	}

	public void setExtendsCard(String extendsCard) {
		this.extendsCard = extendsCard;
	}

	public String getWifiwlan() {
		return wifiwlan;
	}

	public void setWifiwlan(String wifiwlan) {
		this.wifiwlan = wifiwlan;
	}

	public String getGpsDetail() {
		return gpsDetail;
	}

	public void setGpsDetail(String gpsDetail) {
		this.gpsDetail = gpsDetail;
	}

	public String getOtherdigit() {
		return otherdigit;
	}

	public void setOtherdigit(String otherdigit) {
		this.otherdigit = otherdigit;
	}

	public String getMultimedia() {
		return multimedia;
	}

	public void setMultimedia(String multimedia) {
		this.multimedia = multimedia;
	}

	public String getMp3player() {
		return mp3player;
	}

	public void setMp3player(String mp3player) {
		this.mp3player = mp3player;
	}

	public String getVideaplayer() {
		return videaplayer;
	}

	public void setVideaplayer(String videaplayer) {
		this.videaplayer = videaplayer;
	}

	public String getFmRadio() {
		return fmRadio;
	}

	public void setFmRadio(String fmRadio) {
		this.fmRadio = fmRadio;
	}

	public String getFlashplayer() {
		return flashplayer;
	}

	public void setFlashplayer(String flashplayer) {
		this.flashplayer = flashplayer;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getLangId() {
		return langId;
	}

	public void setLangId(int langId) {
		this.langId = langId;
	}

	public int getProductId() {
		return productId;
	}

	public void setProductId(int productId) {
		this.productId = productId;
	}

	public ProductExtendService getProductExtendService() {
		return productExtendService;
	}

	public void setProductExtendService(ProductExtendService productExtendService) {
		this.productExtendService = productExtendService;
	}
	
	
	private int productBaseId;
	
	public int getProductBaseId() {
		return productBaseId;
	}

	public void setProductBaseId(int productBaseId) {
		this.productBaseId = productBaseId;
	}

	public  String productBase() throws Exception{
		productBase = productExtendService.loadProductBaseByProductId(productId);
		return this.SUCCESS;
	}
	public  String deleteProductBase() throws Exception{
		productExtendService.deleteProductBase( productBaseId );
		return this.SUCCESS;
	}
	public String updateProductBase() throws Exception{
		ProductBase bean = new ProductBase();
		bean.setAddressBook(addressBook);
		bean.setMainFunction(mainFunction);
		bean.setMessageFuns(messageFuns);
		bean.setEmailFuns(emailFuns);
		bean.setGame(game);
		bean.setInputMethod(inputMethod);
		bean.setMessageFuns(messageFuns);
		bean.setOfficeFuns(officeFuns);
		bean.setOtherFuns(otherFuns);
		bean.setRecording(recording);
		bean.setRing(ring);
		bean.setWaitTime(waitTime);
		
		bean.setProductId(productId);
		bean.setLangId(langId);
		bean.setId( productBaseId );
		productExtendService.updateProductBase(bean);
		return this.SUCCESS;
	}
	public  String addProductBase() throws Exception{
		ProductBase bean = new ProductBase();
		bean.setAddressBook(addressBook);
		bean.setMainFunction(mainFunction);
		bean.setMessageFuns(messageFuns);
		bean.setEmailFuns(emailFuns);
		bean.setGame(game);
		bean.setInputMethod(inputMethod);
		bean.setMessageFuns(messageFuns);
		bean.setOfficeFuns(officeFuns);
		bean.setOtherFuns(otherFuns);
		bean.setRecording(recording);
		bean.setRing(ring);
		bean.setWaitTime(waitTime);
		
		bean.setProductId(productId);
		bean.setLangId(langId);
		
		productExtendService.insertProductBase(bean );
		return this.SUCCESS;
	}
	
	
	private int productCameraFuncId;
	public int getProductCameraFuncId() {
		return productCameraFuncId;
	}

	public void setProductCameraFuncId(int productCameraFuncId) {
		this.productCameraFuncId = productCameraFuncId;
	}

	public  String productCameraFunc() throws Exception{
		productCameraFunc = productExtendService.loadProductCameraFuncByProductId(productId);
		return this.SUCCESS;
	}
	
	public  String deleteProductCameraFunc() throws Exception{
		productExtendService.deleteProductBase( productCameraFuncId );
		return this.SUCCESS;
	}
	
	public String updateProductCameraFunc() throws Exception{
		ProductCameraFunc bean = new ProductCameraFunc();
		bean.setHeader(header);
		bean.setPixel(pixel);
		bean.setSensorType(sensorType);
		bean.setFlash(flash);
		bean.setSpecial(special);
		bean.setVidea(videa);
		bean.setProductId(productId);
		bean.setLangId(langId);
		bean.setId( productCameraFuncId );
		bean.setPhotoQuality( photoQuality );
		bean.setPhotoEffects( photoEffects );
		bean.setSecondHeader( secondHeader );
		bean.setCaptureMode( captureMode );
 
		productExtendService.updateProductCameraFunc(bean);
		return this.SUCCESS;
	}
	public  String addProductCameraFunc() throws Exception{
		ProductCameraFunc bean = new ProductCameraFunc();
		bean.setHeader(header);
		bean.setPixel(pixel);
		bean.setSensorType(sensorType);
		bean.setFlash(flash);
		bean.setSpecial(special);
		bean.setVidea(videa);
		bean.setPhotoQuality( photoQuality );
		bean.setPhotoEffects( photoEffects );
		bean.setSecondHeader( secondHeader );
		bean.setCaptureMode( captureMode );
		bean.setProductId(productId);
		bean.setLangId(langId);
		
		productExtendService.insertProductCameraFunc(bean );
		return this.SUCCESS;
	}
	
	
	private int productDigiFuncId;
	public int getProductDigiFuncId() {
		return productDigiFuncId;
	}

	public void setProductDigiFuncId(int productDigiFuncId) {
		this.productDigiFuncId = productDigiFuncId;
	}

	public  String productDigiFunc() throws Exception{
		productDigiFunc = productExtendService.loadByProductDigiFuncProductId(productId);
		return this.SUCCESS;
	}
	public  String deleteProductDigiFunc() throws Exception{
		productExtendService.deleteProductBase( productDigiFuncId );
		return this.SUCCESS;
	}
	public String updateProductDigiFunc() throws Exception{
		ProductDigiFunc bean = new ProductDigiFunc();
		bean.setBluetooth(bluetooth);
		bean.setDataService(dataService);
		bean.setJavafunctions(javafunctions);
		bean.setWap(wap);
		bean.setWww(www);
		bean.setDataline(dataline);
		bean.setExtendsCard(extendsCard);
		bean.setWifiwlan(wifiwlan);
		bean.setGpsDetail(gpsDetail);
		bean.setOtherdigit(otherdigit);
	 
		
		bean.setProductId(productId);
		bean.setLangId(langId);
		bean.setId( productDigiFuncId );
		productExtendService.updateProductDigiFunc(bean);
		return this.SUCCESS;
	}
	public  String addProductDigiFunc() throws Exception{
		ProductDigiFunc bean = new ProductDigiFunc();
		bean.setBluetooth(bluetooth);
		bean.setDataService(dataService);
		bean.setJavafunctions(javafunctions);
		bean.setWap(wap);
		bean.setWww(www);
		bean.setDataline(dataline);
		bean.setExtendsCard(extendsCard);
		bean.setWifiwlan(wifiwlan);
		bean.setGpsDetail(gpsDetail);
		bean.setOtherdigit(otherdigit);
		
		bean.setProductId(productId);
		bean.setLangId(langId);
		
		productExtendService.insertProductDigiFunc(bean );
		return this.SUCCESS;
	}
	
	
	private int productMultimediaFuncId;
	public int getProductMultimediaFuncId() {
		return productMultimediaFuncId;
	}

	public void setProductMultimediaFuncId(int productMultimediaFuncId) {
		this.productMultimediaFuncId = productMultimediaFuncId;
	}

	public  String productMultimediaFunc() throws Exception{
		productMultimediaFunc = productExtendService.loadProductMultimediaFuncByProductId(productId);
		return this.SUCCESS;
	}
	public  String deleteMultimediaFunc() throws Exception{
		productExtendService.deleteProductMultimediaFunc( productMultimediaFuncId );
		return this.SUCCESS;
	}
	public String updateProductMultimediaFunc() throws Exception{
		ProductMultimediaFunc bean = new ProductMultimediaFunc();
 
		bean.setMultimedia(multimedia);
		bean.setMp3player(mp3player);
		bean.setVideaplayer(videaplayer);
		bean.setFmRadio(fmRadio);
		bean.setFlashplayer(flashplayer);
		bean.setStreamingMedia(streamingMedia);
		bean.setProductId(productId);
		bean.setLangId(langId);
		bean.setId( productMultimediaFuncId );
		productExtendService.updateProductMultimediaFunc(bean);
		return this.SUCCESS;
	}
	public  String addProductMultimediaFunc() throws Exception{
		ProductMultimediaFunc bean = new ProductMultimediaFunc();
		bean.setMultimedia(multimedia);
		bean.setMp3player(mp3player);
		bean.setVideaplayer(videaplayer);
		bean.setFmRadio(fmRadio);
		bean.setFlashplayer(flashplayer);
		bean.setStreamingMedia(streamingMedia);
		bean.setProductId(productId);
		bean.setLangId(langId);
		
		productExtendService.insertProductMultimediaFunc(bean );
		return this.SUCCESS;
	}
	
	private List<Color> colors ;
	public List<Color> getColors() {
		return colors;
	}

	public void setColors(List<Color> colors) {
		this.colors = colors;
	}

	private String colorName;
	private int colorTypeId;
	private String operateType;
	private int colorId;	
	public String getOperateType() {
		return operateType;
	}

	public int getColorId() {
		return colorId;
	}

	public void setOperateType(String operateType) {
		this.operateType = operateType;
	}

	public void setColorId(int colorId) {
		this.colorId = colorId;
	}
	public int getColorTypeId() {
		return colorTypeId;
	}

	public void setColorTypeId(int colorTypeId) {
		this.colorTypeId = colorTypeId;
	}

	public String getColorName() {
		return colorName;
	}

	public void setColorName(String colorName) {
		this.colorName = colorName;
	}

	public String deleteColor()throws Exception{
		commonService.deleColor(colorId);
		colors = commonService.getColorByProductId(productId);
		return this.SUCCESS;
	}
	public String color()throws Exception{
		if( colorName !=null && !colorName.equals("")){
			Color colorBean = new Color();
			colorBean.setColorName(colorName);
			colorBean.setProductId(productId);
			colorBean.setTypeId(colorTypeId);
			if ( operateType.equals("Add"))
				commonService.addColor(colorBean);
			else {
				colorBean.setId(colorId);
				commonService.updateColor(colorBean);
			}
			colorName = "";
		}
		colors = commonService.getColorByProductId(productId);
		return this.SUCCESS;
	}
	
	public int getPackageComposeId() {
		return packageComposeId;
	}

	public int getPackageTypeId() {
		return packageTypeId;
	}

	public PackageCompose getPackageCompose() {
		return packageCompose;
	}

	public List<PackageCompose> getPackageComposes() {
		return packageComposes;
	}

	public String getCompose() {
		return compose;
	}

	public String getDescription() {
		return description;
	}

	public void setPackageComposeId(int packageComposeId) {
		this.packageComposeId = packageComposeId;
	}

	public void setPackageTypeId(int packageTypeId) {
		this.packageTypeId = packageTypeId;
	}

	public void setPackageCompose(PackageCompose packageCompose) {
		this.packageCompose = packageCompose;
	}

	public void setPackageComposes(List<PackageCompose> packageComposes) {
		this.packageComposes = packageComposes;
	}

	public void setCompose(String compose) {
		this.compose = compose;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getPackageComposePriceStr() {
		return packageComposePriceStr;
	}
	
	public void setPackageComposePriceStr(String packageComposePriceStr) {
		this.packageComposePriceStr = packageComposePriceStr;
	}

	private int packageComposeId;
	private int packageTypeId;
	private PackageCompose packageCompose;
	private List<PackageCompose> packageComposes;
	private String compose;
	private String description;
	private String packageComposePriceStr;

	public String deletePackageCompose()throws Exception{
		commonService.delePackage( packageComposeId);
		packageComposes = commonService.getPackageByProductId(productId);
		return this.SUCCESS;
	}
	public String packageCompose()throws Exception{
		if( compose !=null && !compose.equals("")){
			PackageCompose packageCompose = new PackageCompose();
			packageCompose.setCompose(compose);
			packageCompose.setDescription(description);
			packageCompose.setProductId(productId);
			packageCompose.setTypeId( packageTypeId );
			if ( packageComposePriceStr != null && !packageComposePriceStr.equals("")){
				packageCompose.setPrice( Double.parseDouble( packageComposePriceStr ));
				
			}
			if ( operateType.equals("Add")){
				//commonService.addPackage(packageCompose);
				int packageId=commonService.addPackageGetReturnKey(packageCompose);
				
				Pricehistory bean =new Pricehistory();
				bean.setDescription(compose);
				bean.setStandar( compose );
				int keygroup=OrderUtil.getDateInt();
				bean.setKeygroup(keygroup);
				bean.setPrice( packageCompose.getPrice() );
				bean.setOldprice(packageCompose.getPrice());
				bean.setPackageId(packageId);
				bean.setProductId(productId);
				commonService.addPricehistory(bean );
			}else {
				packageCompose.setId(packageComposeId);
				PackageCompose packageComposeTmp = commonService.getPackageByKey( packageComposeId );
				Pricehistory bean =new Pricehistory();
				bean.setDescription(compose);
				bean.setStandar( compose );
				int keygroup=OrderUtil.getDateInt();
				bean.setKeygroup(keygroup);
				bean.setPrice( packageCompose.getPrice() );
				bean.setOldprice(packageComposeTmp.getPrice());
				bean.setPackageId(packageComposeId);
				bean.setProductId(productId);
				Pricehistory tmp = commonService.checkPriceExist(bean);
				if ( tmp == null){
					commonService.addPricehistory( bean );
				} else {
					bean.setRange( (bean.getPrice()- tmp.getOldprice()) );
					bean.setId(tmp.getId());
					commonService.updatePricehistory( bean );
				}
				commonService.updatePackage( packageCompose);
			}
			compose = "";
			packageComposePriceStr = "";
			operateType = "";
		}
		packageComposes = commonService.getPackageByProductId(productId);
		return this.SUCCESS;
	}
	
	private String content;
	private DetailMsg detailMsg;
	private int detailMsgTypeId;	
	private String detailMsgId;
	public String getDetailMsgId() {
		return detailMsgId;
	}

	public void setDetailMsgId(String detailMsgId) {
		this.detailMsgId = detailMsgId;
	}

	public DetailMsg getDetailMsg() {
		return detailMsg;
	}

	public int getDetailMsgTypeId() {
		return detailMsgTypeId;
	}

	public void setDetailMsg(DetailMsg detailMsg) {
		this.detailMsg = detailMsg;
	}

	public void setDetailMsgTypeId(int detailMsgTypeId) {
		this.detailMsgTypeId = detailMsgTypeId;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	private String operateMsg;
	public String getOperateMsg() {
		return operateMsg;
	}

	public void setOperateMsg(String operateMsg) {
		this.operateMsg = operateMsg;
	}

	public String productDetailMsg() throws Exception{
		operateMsg = "";
		if ("load".equals(operateType )){
			detailMsg = commonService.getDetailMsgByProductId(productId);
			if ( detailMsg == null )
				operateType = "Add";
			else 
				operateType = "Update";
		} else {
			detailMsg = new DetailMsg();
			detailMsg.setDetailMsg(content);
			detailMsg.setProductId(productId);
			detailMsg.setTypeId(detailMsgTypeId);
	 		if( operateType .equals("Add") ){
				commonService.addDetailMsg(detailMsg);
				operateType = "Update";
				operateMsg = "新增手机详细信息成功";
			}else{ 
				if ( detailMsgId !=null && !detailMsgId.equals("")){
				detailMsg.setId(Integer.parseInt(detailMsgId));
				commonService.updateDetailMsg(detailMsg);
				operateType = "Update";
				operateMsg = "更新手机详细信息成功";
				}
			}
		}
		
		return this.SUCCESS;
	}
}
